﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using UnityEngine.SceneManagement;

public class TestEditor
{
    [MenuItem("Window/Test")]
    public static void Test()
    {
        var scene = SceneManager.GetActiveScene();
        foreach (var gameobject in scene.GetRootGameObjects())
        {
            RecursiveObject(gameobject);
            // RecursiveObject(gameobject, (g) =>
            // {
            //     GameObjectUtility.RemoveMonoBehavioursWithMissingScript(gameobject);
            // });
        }
        AssetDatabase.SaveAssets();
    }
    public static void RecursiveObject(GameObject gameObject)
    {
        GameObjectUtility.RemoveMonoBehavioursWithMissingScript(gameObject);
        EditorUtility.SetDirty(gameObject);
        //recursive?.Invoke(gameObject);
        for (int i = 0; i < gameObject.transform.childCount; i++)
        {

            RecursiveObject(gameObject.transform.GetChild(i).gameObject);
            //RecursiveObject(gameObject.transform.GetChild(i).gameObject, recursive);
        }
    }
}
